package com.authService.controller;

import com.authService.pojo.req.MenuEditReqDTO;
import com.authService.pojo.req.MenuPermissionSaveReqDTO;
import com.authService.pojo.req.MenuReqDTO;
import com.authService.pojo.req.MenuUpdateStatusReqDTO;
import com.authService.pojo.res.MenuDetailResDTO;
import com.authService.pojo.res.MenuPermissionRespDTO;
import com.authService.pojo.res.MenuResDTO;
import com.authService.service.ISysMenuPermissionService;
import com.authService.service.ISysMenuService;
import com.xiaopeng.common.httpResult.model.HttpResult;
import com.xiaopeng.common.page.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统菜单表 前端控制器
 * </p>
 *
 * @author xiaopeng
 * @since 2024-09-08
 */
@Tag(name = "系统菜单")
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {

    @Resource
    private ISysMenuService sysMenuService;
    @Resource
    private ISysMenuPermissionService sysMenuPermissionService;

    @Operation(summary = "系统菜单-列表查询")
    @PostMapping("/list")
    public HttpResult<List<MenuResDTO>> list(@RequestBody MenuReqDTO reqDTO) {
        return HttpResult.success(sysMenuService.selectList(reqDTO));
    }

    @Operation(summary = "系统菜单-分页查询")
    @PostMapping("/page")
    public HttpResult<PageVO<MenuResDTO>> page(@RequestBody MenuReqDTO reqDTO) {
        return HttpResult.success(sysMenuService.selectPage(reqDTO));
    }

    @Operation(summary = "系统菜单-详情")
    @GetMapping("/detail")
    public HttpResult<MenuDetailResDTO> detail(@RequestParam Long menuId) {
        return HttpResult.success(sysMenuService.detail(menuId));
    }

    @Operation(summary = "系统菜单-保存")
    @PostMapping("/save")
    public HttpResult<Void> save(@RequestBody @Valid MenuEditReqDTO reqDTO) {
        sysMenuService.saveMenu(reqDTO);
        return HttpResult.success();
    }

    @Operation(summary = "系统菜单-修改")
    @PostMapping("/update")
    public HttpResult<Void> update(@RequestBody @Valid MenuEditReqDTO reqDTO) {
        sysMenuService.updateMenu(reqDTO);
        return HttpResult.success();
    }

    @Operation(summary = "系统菜单-修改启用状态")
    @PostMapping("/update/enableStatus")
    public HttpResult<Void> updateEnableStatus(@RequestBody @Valid MenuUpdateStatusReqDTO reqDTO) {
        sysMenuService.updateEnableStatus(reqDTO);
        return HttpResult.success();
    }
    @Operation(summary = "系统菜单-删除")
    @GetMapping("/delete")
    public HttpResult<Void> delete(@RequestParam Long menuId) {
        sysMenuService.delete(menuId);
        return HttpResult.success();
    }

    @Operation(summary = "系统菜单-权限列表")
    @GetMapping("/permission/list")
    public HttpResult<List<MenuPermissionRespDTO>> selectMenuPermissionList(@RequestParam Long menuId) {
        return HttpResult.success(sysMenuPermissionService.selectMenuPermissionList(menuId));
    }

    @Operation(summary = "系统菜单-权限保存")
    @PostMapping("/permission/save")
    public HttpResult<Void> saveMenuPermission(@RequestBody @Valid MenuPermissionSaveReqDTO reqDTO) {
        sysMenuPermissionService.saveMenuPermission(reqDTO);
        return HttpResult.success();
    }

}
